#!/usr/bin/python

'''Custom logging module.
   Load setting from logging.json config file.
'''

import os
import json
import logging.config
# pylint: disable=W0611
import colorlog

def setup_logging(
        default_path='logging.json',
        default_level=logging.INFO,
        env_key='LOG_CFG'):
    """Setup logging configuration
    """
    path = default_path
    value = os.getenv(env_key, None)
    if value:
        path = value

    if os.path.exists(path):
        with open(path, 'rt') as file:
            config = json.load(file)
        logging.config.dictConfig(config)
    else:
        logging.basicConfig(level=default_level)
